package com.huluobo.a2307douyindemo.shop

import androidx.lifecycle.MutableLiveData
import com.huluobo.lib_base.bean.CartBean
import com.huluobo.lib_base.bean.CommentBean
import com.huluobo.lib_base.bean.GoodsBean
import com.huluobo.lib_base.mvvm.BaseViewModel
import com.huluobo.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2025/9/22.
 */
@HiltViewModel
class ShopViewModel @Inject constructor(private val apiService: ApiService) : BaseViewModel() {

    val getGoodsDetailSuccess by lazy { MutableLiveData<GoodsBean>() }
    fun getGoodsDetail(goodsId: Int) {
        executeNetwork(
            { apiService.getGoodsDetail(goodsId) },
            getGoodsDetailSuccess::postValue
        )
    }

    val getCommentSuccess by lazy { MutableLiveData<List<CommentBean>>() }
    fun getComment() {
        executeNetwork(
            { apiService.getComment(185) },
            getCommentSuccess::postValue
        )
    }

    val addCartSuccess by lazy { MutableLiveData<Any>() }
    fun addCart(body: RequestBody) {
        executeNetwork(
            { apiService.addCart(body) },
            addCartSuccess::postValue
        )
    }

    val getCartSuccess by lazy { MutableLiveData<List<CartBean>>() }
    fun getCart() {
        executeNetwork(
            { apiService.getCart() },
            getCartSuccess::postValue
        )
    }

    val deleteCartSuccess by lazy { MutableLiveData<String>() }
    fun deleteCart(body: RequestBody) {
        executeNetwork(
            { apiService.deleteCart(body) },
            deleteCartSuccess::postValue
        )
    }
}